package com.xzx.flink.streamapi.transform;

import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.Collector;

/**
 * @author xinzhixuan
 * @version 1.0
 * @date 2021-08-24 11:11 下午
 */
public class Transform_02_FlatMap {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStreamSource<String> streamSource = env.readTextFile("/Users/xinzhixuan/work/git/flink-study-java/src/main/resources/sensor.txt");
        SingleOutputStreamOperator<String> flatMap = streamSource.flatMap((String value, Collector<String> out) -> {
            String[] split = value.split(" ");
            for (String s : split) {
                out.collect(s);
            }
        }).returns(String.class);
        flatMap.print();

        env.execute(Transform_02_FlatMap.class.getName());
    }
}
